package com.ramos.kuaixiao.ui;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SearchView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ramos.kuaixiao.App;
import com.ramos.kuaixiao.MyView.refresh.SwipyRefreshLayout;
import com.ramos.kuaixiao.MyView.refresh.SwipyRefreshLayoutDirection;
import com.ramos.kuaixiao.R;
import com.ramos.kuaixiao.adapter.OrderAdapter;
import com.ramos.kuaixiao.db.OrderDB;
import com.ramos.kuaixiao.entity.FindOrderDetail;
import com.ramos.kuaixiao.entity.OrderDetail;
import com.ramos.kuaixiao.utils.CommonLoading;
import com.ramos.kuaixiao.utils.StringUtil;
import com.ramos.kuaixiao.utils.ToastUtils;
import com.ramos.kuaixiao.utils.Utils;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executors;

public class OrderFragment extends Fragment implements OnClickListener, SwipyRefreshLayout.OnRefreshListener {
    private static final String TAG = "OrderFragment";
    private View mView;
    private Context mContext;
    private final int TOP_REFRESH = 1;
    private final int BOTTOM_REFRESH = 2;
    public final static int UPLOAD_SUCCESS = 100;
    public final static int UPLOAD_FAIL = 101;
    private OrderAdapter mAdapter;
    private List<FindOrderDetail> productList = new ArrayList<>();
    private List<FindOrderDetail> temList = new ArrayList<>();
    CommonLoading loading;
    private int page = 1;
    private RecyclerView mRecyclerView;
    private SwipyRefreshLayout mRefreshLayout;
    private LinearLayoutManager mLinearLayoutManager;
    private boolean mIsRefresh = true;
    private LinearLayout ll_unfinished_none;
    TextView tv_all;
    TextView tv_uncheck;
    TextView tv_cancel;
    TextView tv_hang;
    TextView tv_new;
    TextView tv_unusual;
    int currentPage = 1;
    OrderDB db;
    private boolean mIsLocalDB = false;
    SearchView searchview;
    private int filterPage = 1;
    private String mFilterWord;
    private boolean mIsFilter = false;
    private List<FindOrderDetail> mFilterList = new ArrayList<>();
    private List<FindOrderDetail> mPageFilterList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        container = (ViewGroup) mView.getParent();
        if (container != null) {
            container.removeView(mView);
        }
        return mView;
    }

    public void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        initView();
        initLocalDB();
    }

    private void initLocalDB() {
        db = new OrderDB();
        //不再请求在线参数，默认通过服务器获取全部，然后定时同步
        loadLocalDb(1, 1);
    }

    private void loadLocalDb(int page, int currentPage) {
        if (page == 1) {
            productList.clear();
        }
        temList.clear();
        Log.d(TAG, "result " + productList.size());
        temList = db.findAllPageOrder(page, 20, currentPage);
        if (temList.size() > 0) {
            productList.addAll(temList);
            addTasks(productList);
            if (mRefreshLayout != null) {
                mRefreshLayout.setVisibility(View.VISIBLE);
            }
            ll_unfinished_none.setVisibility(View.GONE);
            mAdapter.notifyDataSetChanged();
            Product product = new Product(productList);
            product.executeOnExecutor(Executors.newCachedThreadPool());
        } else if (productList.size() == 0) {
            Log.d(TAG, "result productList 0 ");
            if (mRefreshLayout != null) {
                mRefreshLayout.setVisibility(View.GONE);
            }
            ll_unfinished_none.setVisibility(View.VISIBLE);
        }
        mRefreshLayout.setRefreshing(false);
        mIsRefresh = true;
    }

    private void loadFilterDb(int page, int currentPage) {
        if (page == 1) {
            mPageFilterList.clear();
        }
        temList.clear();

        temList = getPageList(mFilterList, currentPage);
        Log.d(TAG, "result " + temList.size());
        if (temList.size() > 0) {
            mPageFilterList.addAll(temList);
            addTasks(mPageFilterList);
            if (mRefreshLayout != null) {
                mRefreshLayout.setVisibility(View.VISIBLE);
            }
            ll_unfinished_none.setVisibility(View.GONE);

            mAdapter = new OrderAdapter(getActivity(), mPageFilterList);
            mRecyclerView.setAdapter(mAdapter);
            mAdapter.setUpdateCarListener(new UpdateListener());
            //mAdapter.notifyDataSetChanged();
            Product product = new Product(mPageFilterList);
            product.executeOnExecutor(Executors.newCachedThreadPool());
        } else if (mPageFilterList.size() == 0) {
            Log.d(TAG, "result productList 0 ");
            if (mRefreshLayout != null) {
                mRefreshLayout.setVisibility(View.GONE);
            }
            ll_unfinished_none.setVisibility(View.VISIBLE);
        }
        mRefreshLayout.setRefreshing(false);
        mIsRefresh = true;
    }

    private List<FindOrderDetail> getPageList(List<FindOrderDetail> mProducts, int currentPage) {
        List<FindOrderDetail> products = new ArrayList<>();
        List<FindOrderDetail> tmpProducts = new ArrayList<>();
        if (currentPage == 2) {
            for (FindOrderDetail detail : mProducts) {
                if (detail.getOrderStatus().equals("SUBM")) {
                    tmpProducts.add(detail);
                }
            }
        } else if (currentPage == 3) {
            for (FindOrderDetail detail : mProducts) {
                if (detail.getOrderStatus().equals("KEEP")) {
                    tmpProducts.add(detail);
                }
            }
        } else if (currentPage == 4) {
            for (FindOrderDetail detail : mProducts) {
                if (detail.getOrderStatus().equals("HANG")) {
                    tmpProducts.add(detail);
                }
            }
        } else if (currentPage == 5) {
            for (FindOrderDetail detail : mProducts) {
                if (detail.getOrderStatus().equals("CANC")) {
                    tmpProducts.add(detail);
                }
            }
        } else if (currentPage == 6) {
            for (FindOrderDetail detail : mProducts) {
                if (detail.getOrderStatus().equals("SNOE")) {
                    tmpProducts.add(detail);
                }
            }
        } else {
            tmpProducts.addAll(mProducts);
        }
        Log.d(TAG, "tmpProducts " + tmpProducts.size());
        if (tmpProducts.size() <= 20) {
            if (filterPage == 1) {
                products.addAll(tmpProducts);
            }
        } else {
            int maxPage = (tmpProducts.size() - 1) / 20 + 1;
            if (filterPage < maxPage) {
                products.addAll(tmpProducts.subList((filterPage - 1) * 20, filterPage * 20));
            } else if (filterPage == maxPage) {
                products.addAll(tmpProducts.subList((filterPage - 1) * 20, tmpProducts.size()));
                ToastUtils.show("数据已加载完");
            }
        }
        Log.d(TAG, "products " + products.size());
        return products;
    }

    private void initView() {
        mContext = getActivity();
        mView = LayoutInflater.from(mContext).inflate(R.layout.fragment_order, null);
        //mView.findViewById(R.id.title_reback).setVisibility(View.INVISIBLE);
        tv_all = (TextView) mView.findViewById(R.id.tv_all);
        tv_uncheck = (TextView) mView.findViewById(R.id.tv_uncheck);
        tv_hang = (TextView) mView.findViewById(R.id.tv_hang);
        tv_cancel = (TextView) mView.findViewById(R.id.tv_cancel);
        tv_new = (TextView) mView.findViewById(R.id.tv_new);
        tv_unusual = (TextView) mView.findViewById(R.id.tv_unusual);
        tv_all.setOnClickListener(this);
        tv_uncheck.setOnClickListener(this);
        tv_hang.setOnClickListener(this);
        tv_cancel.setOnClickListener(this);
        tv_new.setOnClickListener(this);
        tv_unusual.setOnClickListener(this);
        ll_unfinished_none = (LinearLayout) mView.findViewById(R.id.ll_unfinished_none);
        mRefreshLayout = (SwipyRefreshLayout) mView.findViewById(R.id.allListView);
        mRefreshLayout.setOnRefreshListener(this);
        mRecyclerView = (RecyclerView) mView.findViewById(R.id.list_task);
        mLinearLayoutManager = new LinearLayoutManager(mContext);
        mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(mLinearLayoutManager);
        mAdapter = new OrderAdapter(getActivity(), productList);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setUpdateCarListener(new UpdateListener());
        searchview = mView.findViewById(R.id.shop_Searchview);
        int id = searchview.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = searchview.findViewById(id);
        textView.setTextSize(16);//字体、提示字体大小
        searchview.setQueryHint("搜索订单(至少输入两个字)");
        searchview.setIconified(false);
        searchview.setIconifiedByDefault(false);
        int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
        ImageView magImage = (ImageView) searchview.findViewById(magId);
        magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
        Class<?> c = searchview.getClass();
        try {
            Field f = c.getDeclaredField("mSearchPlate");//通过反射，获得类对象的一个属性对象
            f.setAccessible(true);//设置此私有属性是可访问的
            View v = (View) f.get(searchview);//获得属性的值
            v.setBackgroundColor(Color.TRANSPARENT);//设置此view的背景
        } catch (Exception e) {
            e.printStackTrace();
        }

        searchview.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String arg0) {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public boolean onQueryTextChange(String queryText) {
                mFilterWord = queryText;
                if (StringUtil.isEmpty(queryText)) {
                    if (productList.size() > 0) {
                        mRecyclerView.setVisibility(View.VISIBLE);
                        ll_unfinished_none.setVisibility(View.GONE);
                        mAdapter.refresh(productList);
                    }
                    mIsFilter = false;
                } else if (queryText.length() >= 2) {
                    mIsFilter = true;
                    mAdapter.getFilter().filter(queryText);
                }
                return true;
            }
        });
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        //可以在这里直接去处理fragment的hide和show
        searchview.clearFocus();
    }

    @Override
    public void onResume() {
        super.onResume();
        searchview.clearFocus();
    }

    class UpdateListener implements OrderAdapter.UpdateCarListener {
        @Override
        public void update(int num, List<FindOrderDetail> tasklist) {
            if (tasklist == null || tasklist.size() == 0) {
                if (!StringUtil.isEmpty(mFilterWord)) {
                    mRecyclerView.setVisibility(View.GONE);
                    ll_unfinished_none.setVisibility(View.VISIBLE);
                }
            } else {
                mPageFilterList.clear();
                mFilterList.clear();
                mFilterList.addAll(tasklist);
                filterPage = 1;
                loadFilterDb(1, currentPage);
            }
        }
    }


    @SuppressLint("HandlerLeak")
    Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case UPLOAD_SUCCESS:
                    if (page == 1) {
                        App.ORDER_RESULT = msg.obj.toString();
                        productList.clear();
                    }
                    temList.clear();
                    Log.d(TAG, "result " + msg.obj.toString());
                    Log.d(TAG, "result " + productList.size());
                    JSONObject jsonObejct = JSONObject.parseObject(msg.obj.toString());
                    JSONObject data = jsonObejct.getJSONObject("data");
                    temList = JSONArray.parseArray(data.getJSONArray("rows").toString(), FindOrderDetail.class);
                    if (temList.size() > 0) {
                        productList.addAll(temList);
                        if (mRefreshLayout != null) {
                            mRefreshLayout.setVisibility(View.VISIBLE);
                        }
                        ll_unfinished_none.setVisibility(View.GONE);
                        //mAdapter.notifyDataSetChanged();
                        addTasks(productList);
                        mAdapter = new OrderAdapter(getActivity(), productList);
                        mRecyclerView.setAdapter(mAdapter);
                        Product product = new Product(productList);
                        product.executeOnExecutor(Executors.newCachedThreadPool());
                    } else if (productList.size() == 0) {
                        Log.d(TAG, "result productList 0 ");
                        if (mRefreshLayout != null) {
                            mRefreshLayout.setVisibility(View.GONE);
                        }
                        ll_unfinished_none.setVisibility(View.VISIBLE);
                    }
                    mRefreshLayout.setRefreshing(false);
                    mIsRefresh = true;
                    break;
                case UPLOAD_FAIL:
                    mRefreshLayout.setRefreshing(false);
                    if (productList.size() == 0) {
                        if (mRefreshLayout != null) {
                            mRefreshLayout.setVisibility(View.GONE);
                        }
                        ll_unfinished_none.setVisibility(View.VISIBLE);
                    }
                    mIsRefresh = true;
                    break;
                default:
                    break;
            }
        }
    };

    private void addTasks(List<FindOrderDetail> orders) {
        Collections.sort(orders, new Comparator<FindOrderDetail>() {

            @Override
            public int compare(FindOrderDetail o1, FindOrderDetail o2) {
                long time1 = 0;
                long time2 = 0;
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
                    Date date = new Date();
                    time1 = sdf.parse(o1.getOrderDate()).getTime();
                    time2 = sdf.parse(o2.getOrderDate()).getTime();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // 按照时间进行降序排列
                if (time1 > time2) {
                    return -1;
                }
                if (time1 == time2) {
                    return 0;
                }
                return 1;
            }
        });
    }

    @Override
    public void onRefresh(SwipyRefreshLayoutDirection direction) {
        if (mIsFilter) {
            if (direction == SwipyRefreshLayoutDirection.BOTTOM) {
                ++filterPage;
                List<FindOrderDetail> products = getPageList(mFilterList, currentPage);
                if (products.size() > 0) {
                    mPageFilterList.addAll(products);
                    mAdapter.notifyDataSetChanged();
                    Product product = new Product(mPageFilterList);
                    product.executeOnExecutor(Executors.newCachedThreadPool());
                }
                mRefreshLayout.setRefreshing(false);
            } else {
                mRefreshLayout.setRefreshing(false);
            }
        } else {
            if (direction == SwipyRefreshLayoutDirection.TOP) {
                mIsRefresh = false;
                dataOption(TOP_REFRESH);
            } else {
                mIsRefresh = false;
                dataOption(BOTTOM_REFRESH);
            }
        }
    }

    class Product extends AsyncTask<String, String, String> {
        List<FindOrderDetail> list;
        List<OrderDetail> detaillist;
        List<String> orderImageList;

        public Product(List<FindOrderDetail> type) {
            list = type;
        }

        @Override
        protected String doInBackground(String... params) {
            try {
                for (int i = 0; i < list.size(); i++) {
                    detaillist = JSONArray.parseArray(list.get(i).getOrderDetailList(), OrderDetail.class);
                    orderImageList = new ArrayList<>();
                    if (detaillist != null && detaillist.size() > 0) {
                        for (OrderDetail orderDetail : detaillist) {
                            String imgURL = Utils.showImg(orderDetail.getProductInfoId(), orderDetail.getProductBarCode());
                            if (!StringUtil.isEmpty(imgURL)) {
                                orderImageList.add(imgURL);
                            }
                        }
                    }
                    list.get(i).setOrderImageList(orderImageList);
                    Log.d("Product", "orderImageList " + i + " " + orderImageList.size());
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            Log.d("Product", "onPostExecute " + list.size());

            mAdapter.notifyDataSetChanged();
        }
    }

    private void sendMessagea(int iWhat, Object obj) {
        Message msg = Message.obtain();
        msg.what = iWhat;
        msg.obj = obj;
        mHandler.sendMessage(msg);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_all:
                if (currentPage != 1) {
                    page = 1;
                    currentPage = 1;
                    if (mIsFilter) {
                        loadFilterDb(1, 1);
                    } else {
                        if (mIsLocalDB || db.hasData()) {
                            loadLocalDb(1, 1);
                        }
                    }
                    //initData(1, 1);
                    setText(1);
                }
                break;

            case R.id.tv_new:
                if (currentPage != 2) {
                    page = 1;
                    currentPage = 2;
                    if (mIsFilter) {
                        loadFilterDb(1, 2);
                    } else {
                        if (mIsLocalDB || db.hasData()) {
                            loadLocalDb(1, 2);
                        }
                    }
                    //initData(1, 2);
                    setText(2);
                }
                break;
            case R.id.tv_uncheck:
                if (currentPage != 3) {
                    page = 1;
                    currentPage = 3;
                    if (mIsFilter) {
                        loadFilterDb(1, 3);
                    } else {
                        if (mIsLocalDB || db.hasData()) {
                            loadLocalDb(1, 3);
                        }
                    }
                    //initData(1, 3);
                    setText(3);
                }
                break;
            case R.id.tv_hang:
                if (currentPage != 4) {
                    page = 1;
                    currentPage = 4;
                    if (mIsFilter) {
                        loadFilterDb(1, 4);
                    } else {
                        if (mIsLocalDB || db.hasData()) {
                            loadLocalDb(1, 4);
                        }
                    }
                    //initData(1, 4);
                    setText(4);
                }
                break;
            case R.id.tv_cancel:
                if (currentPage != 5) {
                    page = 1;
                    currentPage = 5;
                    if (mIsFilter) {
                        loadFilterDb(1, 5);
                    } else {
                        if (mIsLocalDB || db.hasData()) {
                            loadLocalDb(1, 5);
                        }
                    }
                    //initData(1, 4);
                    setText(5);
                }
                break;

            case R.id.tv_unusual:
                if (currentPage != 6) {
                    page = 1;
                    currentPage = 6;
                    if (mIsFilter) {
                        loadFilterDb(1, 6);
                    } else {
                        if (mIsLocalDB || db.hasData()) {
                            loadLocalDb(1, 6);
                        }
                    }
                    //initData(1, 4);
                    setText(6);
                }
                break;
            default:
                break;
        }
    }


    private void setText(int i) {
        if (i == 1) {
            tv_all.setTextColor(getResources().getColor(R.color.title));
            tv_new.setTextColor(getResources().getColor(R.color.black));
            tv_uncheck.setTextColor(getResources().getColor(R.color.black));
            tv_hang.setTextColor(getResources().getColor(R.color.black));
            tv_cancel.setTextColor(getResources().getColor(R.color.black));
            tv_unusual.setTextColor(getResources().getColor(R.color.black));
            tv_all.setBackgroundColor(getResources().getColor(R.color.adjust_line));
            tv_new.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_uncheck.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_hang.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_cancel.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_unusual.setBackgroundColor(getResources().getColor(R.color.color_white));
        } else if (i == 2) {
            tv_all.setTextColor(getResources().getColor(R.color.black));
            tv_new.setTextColor(getResources().getColor(R.color.title));
            tv_uncheck.setTextColor(getResources().getColor(R.color.black));
            tv_hang.setTextColor(getResources().getColor(R.color.black));
            tv_cancel.setTextColor(getResources().getColor(R.color.black));
            tv_unusual.setTextColor(getResources().getColor(R.color.black));
            tv_all.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_new.setBackgroundColor(getResources().getColor(R.color.adjust_line));
            tv_uncheck.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_hang.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_cancel.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_unusual.setBackgroundColor(getResources().getColor(R.color.color_white));
        } else if (i == 3) {
            tv_all.setTextColor(getResources().getColor(R.color.black));
            tv_new.setTextColor(getResources().getColor(R.color.black));
            tv_uncheck.setTextColor(getResources().getColor(R.color.title));
            tv_hang.setTextColor(getResources().getColor(R.color.black));
            tv_cancel.setTextColor(getResources().getColor(R.color.black));
            tv_unusual.setTextColor(getResources().getColor(R.color.black));
            tv_all.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_new.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_uncheck.setBackgroundColor(getResources().getColor(R.color.adjust_line));
            tv_hang.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_cancel.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_unusual.setBackgroundColor(getResources().getColor(R.color.color_white));
        } else if (i == 4) {
            tv_all.setTextColor(getResources().getColor(R.color.black));
            tv_new.setTextColor(getResources().getColor(R.color.black));
            tv_uncheck.setTextColor(getResources().getColor(R.color.black));
            tv_hang.setTextColor(getResources().getColor(R.color.title));
            tv_cancel.setTextColor(getResources().getColor(R.color.black));
            tv_unusual.setTextColor(getResources().getColor(R.color.black));
            tv_all.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_new.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_uncheck.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_hang.setBackgroundColor(getResources().getColor(R.color.adjust_line));
            tv_cancel.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_unusual.setBackgroundColor(getResources().getColor(R.color.color_white));
        } else if (i == 5) {
            tv_all.setTextColor(getResources().getColor(R.color.black));
            tv_new.setTextColor(getResources().getColor(R.color.black));
            tv_uncheck.setTextColor(getResources().getColor(R.color.black));
            tv_hang.setTextColor(getResources().getColor(R.color.black));
            tv_cancel.setTextColor(getResources().getColor(R.color.title));
            tv_unusual.setTextColor(getResources().getColor(R.color.black));
            tv_all.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_new.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_uncheck.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_hang.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_cancel.setBackgroundColor(getResources().getColor(R.color.adjust_line));
            tv_unusual.setBackgroundColor(getResources().getColor(R.color.color_white));
        } else if (i == 6) {
            tv_all.setTextColor(getResources().getColor(R.color.black));
            tv_new.setTextColor(getResources().getColor(R.color.black));
            tv_uncheck.setTextColor(getResources().getColor(R.color.black));
            tv_hang.setTextColor(getResources().getColor(R.color.black));
            tv_cancel.setTextColor(getResources().getColor(R.color.black));
            tv_unusual.setTextColor(getResources().getColor(R.color.title));
            tv_all.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_new.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_uncheck.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_hang.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_cancel.setBackgroundColor(getResources().getColor(R.color.color_white));
            tv_unusual.setBackgroundColor(getResources().getColor(R.color.adjust_line));
        }
    }

    private void dataOption(int option) {
        switch (option) {
            case TOP_REFRESH:
                // 下拉刷新
                productList.clear();
                page = 1;
                if (mIsLocalDB || db.hasData()) {
                    loadLocalDb(page, currentPage);
                }
                break;
            case BOTTOM_REFRESH:
                // 上拉加载更多
                page++;
                if (mIsLocalDB || db.hasData()) {
                    loadLocalDb(page, currentPage);
                }
                break;
        }
    }
}